package com.uwo.house.controller;

import com.uwo.house.service.serviceImpl.PermissmionService;
import com.uwo.house.util.UtilReturn;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by yanhao on 2017/7/19.
 */
@Controller
@RequestMapping("/permission")
public class PermissmionController {

    @Autowired
    private PermissmionService permissmionService;


    @RequiresPermissions("permission:init")
    @RequestMapping(value = {"", "/"})
    @ResponseBody
    public Object init(){
        return "init";
    }

    @RequiresPermissions("permission:save")
    @RequestMapping(value = "/save")
    @ResponseBody
    public Object save(){
        return "save";
    }

    @RequiresPermissions("permission:modify")
    @RequestMapping(value = "/modify")
    @ResponseBody
    public Object modify(){
        return "modify";
    }

    @RequiresPermissions("permission:remove")
    @RequestMapping(value = "/{id}")
    @ResponseBody
    public Object remove(@PathVariable Long id){
        int count = permissmionService.remvoe(id);
        if(count > 0)
            return UtilReturn.resSuccesssMap(UtilReturn.SUCCESS_STATUS, UtilReturn.SUCCESS_CODE, null);
        return UtilReturn.resErrorMap(UtilReturn.ERROR_STATUS, UtilReturn.ERROR_CODE);
    }

    @RequiresPermissions("permission:role")
    @RequestMapping(value = "/role")
    @ResponseBody
    public Object user(){
        return "role";
    }


}
